<?php //use_javascript('chatBar/musique.js')                                               ?>

<div id="musique"></div>
<div id="footpanel" style="position:fixed; border-bottom: 0px;">
    <ul id="mainpanel" style="width: 100%">

        <li id="chatpanel">
            <a class="chat" style="border-left: 1px solid #bbb; border-right: 1px solid #bbb;" >Membres (<strong id="nombre_connected_friends">0</strong>) </a>
            <div class="subpanel" >
                <!--                <div class="entete">
                                    <h2><span> &ndash; </span>Membres connectés</h2>
                                </div>-->
                <ul style="height: 100%;">
                    <li>
                        <span>Employés</span>
                        <img id="image_connected" src="/images/icone/connected.jpg"/>
                        <img id="image_not_connected" style="display: none" src="/images/icone/not_connected.jpg"/>
                    </li>
                    <div id="connectedUsers" style="width: 96.5%;height: 300px;overflow:scroll; overflow-y: auto; overflow-x:hidden; position: relative;">
                    </div>
                </ul>
            </div>
        </li>
        <!--        <li>
        <?php if ($sf_user->getAttribute('alert', 'true') == 'true'): ?>
                                                                                                                                                                <a id="alert_configure" class="sound" href="#" onclick="javascript:alertDesactivate()">Désactiver le son</a>
        <?php else: ?>
                                                                                                                                                                <a id="alert_configure" class="mute" href="#" onclick="javascript:alertActivate()">Activer le son</a>
        <?php endif; ?>
                </li>-->
    </ul>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $('#image_connected').click(function(){
            $(this).hide();
            $('#image_not_connected').show();
            connected_users = "false";
        });
        $('#image_not_connected').click(function(){
            $(this).hide();
            $('#image_connected').show();
            connected_users = "true";
        });
        //Adjust panel height
        $.fn.adjustPanel = function(){
            $(this).find("ul, .subpanel").css({ 'height' : 'auto'}); //Reset subpanel and ul height

            var windowHeight = 400;//$(window).height(); //Get the height of the browser viewport
            var panelsub = $(this).find(".subpanel").height(); //Get the height of subpanel
            var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of subpanel)
            var ulAdjust =  panelAdjust - 25; //Calculate ul size after adjusting sub-panel (27px is the height of the base panel)

            if ( panelsub >= panelAdjust ) {	 //If subpanel is taller than max height...
                $(this).find(".subpanel").css({ 'height' : panelAdjust }); //Adjust subpanel to max height
                $(this).find("ul").css({ 'height' : ulAdjust}); //Adjust subpanel ul to new size
            }
            else if ( panelsub < panelAdjust ) { //If subpanel is smaller than max height...
                $(this).find("ul").css({ 'height' : 'auto'}); //Set subpanel ul to auto (default size)
            }
        };

        //Execute function on load
        $("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel
        $("#alertpanel").adjustPanel(); //Run the adjustPanel function on #alertpanel
        $(".chatFriend").adjustPanel(); //Run the adjustPanel function on .chatFriend

        //Each time the viewport is adjusted/resized, execute the function
        $(window).resize(function () {
            $("#chatpanel").adjustPanel();
            $("#alertpanel").adjustPanel();
            $(".chatFriend").adjustPanel();
        });

        //Click event on Chat Panel + Alert Panel
        $("#chatpanel a:first, #alertpanel a:first").click(function() { //If clicked on the first link of #chatpanel and #alertpanel...
            if($(this).next(".subpanel").is(':visible')){ //If subpanel is already active...
                $(this).next(".subpanel").hide(); //Hide active subpanel
                $("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger
                $("#footpanel li a").removeClass('active');
            }
            else { //if subpanel is not active...
                $(".subpanel").hide(); //Hide all subpanels
                $(this).next(".subpanel").toggle(); //Toggle the subpanel to make active
                $("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger
                $("#footpanel li a").removeClass('active');
                $(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
            }
            return false; //Prevent browser jump to link anchor
        });

        //Click event outside of subpanel
        $(document).click(function() { //Click anywhere and...
            $(".subpanel").hide(); //hide subpanel
            $("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
        });
        $(".chatFriend h3:first").click(function() { //If clicked on the first link of #chatpanel and #alertpanel...
            $(".subpanelFriend").hide(); //hide subpanel
            $("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
        });
        $('.subpanel ul').click(function(e) {
            e.stopPropagation(); //Prevents the subpanel ul from closing on click
        });
        $('.subpanelFriend ul').click(function(e) {
            e.stopPropagation(); //Prevents the subpanel ul from closing on click
        });
    });
    function upload(id){
        $('#upload_file').bPopup();
        $('#upload_file').bPopup().close();
        $('#upload_file').bPopup();
        $('#id_chat').val(id);
    }
    function annulerUpload(){
        recupererFichiers()
        liste_fichiers = new Array();
        var files_uploaded = $('#file_uploaded').val();
        while(files_uploaded.indexOf(':')>0){
            var file = files_uploaded.substring(0, files_uploaded.indexOf(':'));
            liste_fichiers.push(file)
            files_uploaded = files_uploaded.substring(files_uploaded.indexOf(':')+1);
        }
        $('#valider_upload').hide();
        $('#annuler_upload').hide();
        $('#lancer_upload').show();
        $('#clear_queue').show();
        $('#uploadifyUploader').show();
        $('#fileAttente div').remove();
        $('#upload_file').bPopup().close();
        for(var k=0;k<liste_fichiers.length;k++){
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: '<?php echo url_for('@ajaxDeleteFileFromUploads') ?>',
                data: 'file='+liste_fichiers[k],
                success: function(data)
                {
                }
            });
        }
        
    }
    function validerUpload(){
        
        var id = $('#id_chat').val()
        recupererFichiers()
        liste_fichiers = new Array();
        var files_uploaded = $('#file_uploaded').val();
        while(files_uploaded.indexOf(':')>0){
            var file = files_uploaded.substring(0, files_uploaded.indexOf(':'));
            liste_fichiers.push(file)
            files_uploaded = files_uploaded.substring(files_uploaded.indexOf(':')+1);
        }
        $('#valider_upload').hide();
        $('#annuler_upload').hide();
        $('#lancer_upload').show();
        $('#clear_queue').show();
        $('#uploadifyUploader').show();
        $('#fileAttente div').remove();
        $('#upload_file').bPopup().close();
        for(var k=0;k<liste_fichiers.length;k++){
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: '<?php echo url_for('@ajaxSendMessage') ?>',
                data: 'contenu='+liste_fichiers[k]+'&receiver_id='+id+'&file='+'is_file',
                success: function(data)
                {
                    data_send = data.message['contenu']
                    //var maVar = $("#message_container_"+id).scrollTop()
                    var heure = data.message['date_envoi'].split(' ')[1].split(':')[0];
                    var minute = data.message['date_envoi'].split(' ')[1].split(':')[1];
                    var seconde = data.message['date_envoi'].split(' ')[1].split(':')[2];
                    $("#message_container_"+id).append('<li>'+
                        '<div class="metaInfoContainerChat"><span><b>Moi</b></span><span class="timestampChat">'+heure+':'+minute+':'+seconde+'</span>'+
                        '<br><span><a href="<?php echo url_for('@homepage'); ?>'+'download_file/'+data.message['cmp_file']+'">'+data_send+'</a></span></div></li>');
                    $("#message_container_"+id).scrollTop(maVar+500)
                }
            });
        }
    }

    function openChatText(id, user_name)
    {
        if(document.getElementById("chatFriend_"+id) == null) {
            //To hide panel of list members
            $(".subpanel").hide(); //hide subpanel
            $("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
            //To create chatPanel
            $("#mainpanel").append(''+
                '<li class="chatFriend" style="border-right: 1px solid #bbb; border-left: 1px solid #bbb;" id="chatFriend_'+id+'">'+
                '<span id="num_message_'+id+'" class="numMessages hidden_num" style="top: -8px;">0</span>'+
                '<textarea class="chatText" id="chatText_'+id+'" style="width: 234px; height: 26px;resize: none;border: none;font-size: 13px;"></textarea>'+
                '<i style="left: 6px;position: absolute;top: 5px;"><img src="/images/icone/icone_message.png" style="width: 12px; height: 12px;" /></i>'+
                '<div class="subpanelFriend" id="subpanelFriend'+id+'" style="height: 275px;display: block;border-radius:5px 5px 0px 0px;bottom:27px;width:233px">'+
                // title bar
            '<div class="entete">'+
                '<h2 style="color:blue">'+
                user_name+
                '<img onclick="upload('+id+')" src="/images/icon/attach.png" style=" width: 16px; height: 16px; margin: 10px; text-indent: -9999px; cursor: pointer;">'+
                '<img onclick="javascript:closeChatPanel('+id+')" alt="" src="/images/chatBar/delete_x.gif" style="float: right; width: 13px; height: 14px; margin: 1px; text-indent: -9999px; cursor: pointer;">'+
                '</h2>'+
                '</div>'+
                // conversation container
            '<div class="chatBody" style="height: 227px;">'+
                '<div class="message_container" id="message_container_'+id+'" style="height: 100%; overflow-y: auto; overflow-x:hidden; position: relative;">'+
                '</div>'+
                '</div>'+
                // input container
            '<div>'+
                
                '</div>'+
                '</div>'+
                '</li>');
            //To open chatFriend panel
            $(".subpanel").hide(); //Hide all subpanels
            $("#chatFriend_"+id+" a:first").next(".subpanelFriend").toggle(); //Toggle the subpanel to make active
            $("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger
            $("#chatFriend_"+id+" a:first").toggleClass('active'); //Toggle the active class on the subpanel trigger
            ///
            var lot_old_msg = 10;
            var len_ancien_data = 0;
            var msg_ancien = true;
            var first_old_msg = true;
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: '<?php echo url_for('@ajaxGetOldMessages') ?>',
                data: 'lot_old_msg='+lot_old_msg+'&receiver_id='+id,
                success: function(data)
                {
                    len_ancien_data = data.length;
                    for(var i=0;i<data.length;i++){
                        data_send = data[i]['contenu']
                        cmp_file = data[i]['cmp_file']
                        if(cmp_file=="0"){
                            var lignes= new Array();
                            var cmp = 0
                            while(data_send.length > 40){
                                var j = 40
                                while(data_send.substr(j,1)!=' ' && j!=0)
                                    j--
                                if(j==0)
                                    j=40
                                lignes[cmp] = data_send.substr(0,j)
                                data_send = data_send.substr(j)
                                cmp++
                            }
                            lignes[cmp] = data_send
                            data_send=""
                            for(var k=0;k<lignes.length;k++){
                                data_send+=lignes[k]+'<br>'
                            }
                        }
                        var maVar = $("#message_container_"+id).scrollTop()
                        var jour = data[i]['date'].split(' ')[0].split('-')[2];
                        var mois = data[i]['date'].split(' ')[0].split('-')[1];
                        var annee = data[i]['date'].split(' ')[0].split('-')[0];
                        var heure = data[i]['date'].split(' ')[1].split(':')[0];
                        var minute = data[i]['date'].split(' ')[1].split(':')[1];
                        sender = ""
                        if(data[i]['me']=="me")
                            sender = "Moi"
                        else
                            sender = user_name
                        var contenu;
                        if(cmp_file=="0")
                            contenu = '<br><span>'+data_send+'</span></div></li>';
                        else
                            contenu = '<br><span><a href="<?php echo url_for('@homepage'); ?>'+'download_file/'+cmp_file+'">'+data_send+'</a></span></div></li>';
                        $("#message_container_"+id).append('<li>'+
                            '<div class="metaInfoContainerChat"><span><b>'+sender+'</b></span><span class="timestampChat">'+jour+'/'+mois+'/'+annee+'  '+heure+':'+minute+'</span>'+
                            contenu);
                        $("#message_container_"+id).scrollTop(maVar+500)
                        first_old_msg = false; 
                    }
                }
               
            });
            $("#message_container_"+id).scroll(function(){
                var maVar = 1
                if(!first_old_msg)
                    maVar = $("#message_container_"+id).scrollTop()
                if(maVar == 0 && msg_ancien){
                    lot_msg = 10
                    lot_old_msg+=lot_msg
                    $("#message_container_"+id).empty()
                    $.ajax({
                        type: 'GET',
                        dataType: 'json',
                        url: '<?php echo url_for('@ajaxGetOldMessages') ?>',
                        data: 'lot_old_msg='+lot_old_msg+'&receiver_id='+id,
                        success: function(data)
                        {
                            for(var i=0;i<data.length;i++){
                                cmp_file = data[i]['cmp_file']
                                data_send = data[i]['contenu']
                                if(cmp_file=="0"){
                                    var lignes= new Array();
                                    var cmp = 0
                                    while(data_send.length > 40){
                                        var j = 40
                                        while(data_send.substr(j,1)!=' ' && j!=0)
                                            j--
                                        if(j==0)
                                            j=40
                                        lignes[cmp] = data_send.substr(0,j)
                                        data_send = data_send.substr(j)
                                        cmp++
                                    }
                                    lignes[cmp] = data_send
                                    data_send=""
                                    for(var k=0;k<lignes.length;k++){
                                        data_send+=lignes[k]+'<br>'
                                    }
                                }
                                var maVar = $("#message_container_"+id).scrollTop()
                                var jour = data[i]['date'].split(' ')[0].split('-')[2];
                                var mois = data[i]['date'].split(' ')[0].split('-')[1];
                                var annee = data[i]['date'].split(' ')[0].split('-')[0];
                                var heure = data[i]['date'].split(' ')[1].split(':')[0];
                                var minute = data[i]['date'].split(' ')[1].split(':')[1];
                                sender = ""
                                if(data[i]['me']=="me")
                                    sender = "Moi"
                                else
                                    sender = user_name
                                if(cmp_file=="0")
                                    contenu = '<br><span>'+data_send+'</span></div></li>';
                                else
                                    contenu = '<br><span><a href="<?php echo url_for('@homepage'); ?>'+'download_file/'+cmp_file+'">'+data_send+'</a></span></div></li>';
                                
                                $("#message_container_"+id).append('<li>'+
                                    '<div class="metaInfoContainerChat"><span><b>'+sender+'</b></span><span class="timestampChat">'+jour+'/'+mois+'/'+annee+'  '+heure+':'+minute+'</span>'+
                                    contenu);
                                $("#message_container_"+id).scrollTop(maVar+500)
                            }
                            $("#message_container_"+id).scrollTop(200)
                            if(data.length<len_ancien_data+lot_msg)
                                msg_ancien = false;
                            else
                                len_ancien_data = data.length
                        }
                
                    });
                }
            
            });
            $("#chatText_"+id).keyup(function(e) {
                if(e.keyCode == 13) {
                    if($("#chatText_"+id).val().trim() == ""){
                        $("#chatText_"+id).val('');
                    }else{
                        contenu=$("#chatText_"+id).val();
                        $.ajax({
                            type: 'GET',
                            dataType: 'json',
                            url: '<?php echo url_for('@ajaxSendMessage') ?>',
                            data: 'contenu='+$("#chatText_"+id).val()+'&receiver_id='+id,
                            success: function(data)
                            {
                                data_send = data.message['contenu']
                                var lignes= new Array();
                                var cmp = 0
                                while(data_send.length > 40){
                                    var i = 40
                                    while(data_send.substr(i,1)!=' ' && i!=0)
                                        i--
                                    if(i==0)
                                        i=40
                                    lignes[cmp] = data_send.substr(0,i)
                                    data_send = data_send.substr(i)
                                    cmp++
                                }
                                lignes[cmp] = data_send
                                data_send=""
                                for(var i=0;i<lignes.length;i++){
                                    data_send+=lignes[i]+'<br>'
                                }
                                var maVar = $("#message_container_"+id).scrollTop()
                                var heure = data.message['date_envoi'].split(' ')[1].split(':')[0];
                                var minute = data.message['date_envoi'].split(' ')[1].split(':')[1];
                                $("#message_container_"+id).append('<li>'+
                                    '<div class="metaInfoContainerChat"><span><b>Moi</b></span><span class="timestampChat">'+heure+':'+minute+'</span>'+
                                    '<br><span>'+data_send+'</span></div></li>');
                                $("#message_container_"+id).scrollTop(maVar+500)
                            }
                        });
                        $("#chatText_"+id).val('');
                    } 
                }
            });
        }
    }
    jQuery.timer = function (interval, callback)
    {
        var interval = interval || 100;
        if (!callback)
            return false;

        _timer = function (interval, callback) {
            this.stop = function () {
                clearInterval(self.id);
            };

            this.internalCallback = function () {
                callback(self);
            };

            this.reset = function (val) {
                if (self.id)
                    clearInterval(self.id);

                var val = val || 100;
                this.id = setInterval(this.internalCallback, val);
            };
            this.interval = interval;
            this.id = setInterval(this.internalCallback, this.interval);
            var self = this;
        };

        return new _timer(interval, callback);
    };
    var instance = null;
    connected_users = "true";
    $.timer(3000, function (timer) {
        $.ajax({
            
            type: 'POST',
            dataType: 'json',
            url: '<?php echo url_for('@ajaxUpdateInstant') ?>',
            data: 'connected_users='+connected_users,
            success: function(data)
            {
                // actualiser le nombre de courriers dans le menu horizontal
                // var courriers_nombre = data.courriers_nombre;
                //                $("#courriers_number").html(courriers_nombre);
                //                $("#nb_courriers_non_lus").html(" ("+courriers_nombre+")");
                //                if(courriers_nombre > 0) {
                //                    $("#courriers_number").removeClass('hidden_num');
                //                    $("#courriers_number").addClass('shown_num');
                //                } else {
                //                    $("#courriers_number").removeClass('shown_num');
                //                    $("#courriers_number").addClass('hidden_num');
                //                }

                ///////
                var nb_connected = data.connectedFriends.length;
                //                var nb_notifications = data.notifications.length;
                //                var nb_notify = data.notify.length;
                var nb_messages = data.messages.length;

                // if((nb_messages > 0) && (data.alerte == 'true'))
                //                    jouer_musique();

                for (s = 0; s < nb_messages; s++) {
                    var heure = data.messages[s]['date_envoi'].split(' ')[1].split(':')[0];
                    var minute = data.messages[s]['date_envoi'].split(' ')[1].split(':')[1];
                    // si le chatText est fermé
                    // ouvrir le chatText
                    if(document.getElementById("chatFriend_"+data.messages[s]['sender_id']) == null) {
                        openChatText(data.messages[s]['sender_id'], data.messages[s]['sender_name'], 'false');
                        $("#num_message_"+data.messages[s]['sender_id']).removeClass('shown_num');
                        $("#num_message_"+data.messages[s]['sender_id']).addClass('hidden_num');
                    } else {
                        // si le chat text est fermé
                        if($("#chatFriend_"+data.messages[s]['sender_id']).find('.subpanelFriend').css('display') == "none") {
                            var nb = parseInt($("#num_message_"+data.messages[s]['sender_id']).html());
                            $("#num_message_"+data.messages[s]['sender_id']).html(nb + 1);
                            $("#num_message_"+data.messages[s]['sender_id']).removeClass('hidden_num');
                            $("#num_message_"+data.messages[s]['sender_id']).addClass('shown_num');
                        }
                    }

                    // si le chatText est ouvert
                    maVar = $("#message_container_"+data.messages[s]['sender_id']).scrollTop()
                    var contenu = "";
                    var cmp_file = data.messages[s]['cmp_file'];
                    if(cmp_file=="0")
                        contenu = '<br><span>'+data.messages[s]['contenu']+'</span></div></li>';
                    else
                        contenu = '<br><span><a href="<?php echo url_for('@homepage'); ?>'+'download_file/'+cmp_file+'">'+data.messages[s]['contenu']+'</a></span></div></li>'; 
                    $("#message_container_"+data.messages[s]['sender_id']).append('<li>'+
                        '<div class="metaInfoContainerChat"><span><b>'+data.messages[s]['sender_name']+'</b></span><span class="timestampChat">'+heure+':'+minute+'</span>'+
                        contenu);
                    $("#message_container_"+data.messages[s]['sender_id']).scrollTop(maVar+500)
                }

                $("#nombre_connected_friends").html(nb_connected);

                $("#connectedUsers").empty();
                for (i = 0; i < nb_connected; i++) {
                    $("#connectedUsers").append('<li id="friend"><a onclick="openChatText('+data.connectedFriends[i]['id']+', \''+data.connectedFriends[i]['name']+'\')"><img alt="" src="/images/chatBar/chat-thumb.gif">'+data.connectedFriends[i]['name']+'</a></li>');
                }
            }});
    });
    function demandeAmisNotification(notification_id,medecin_id){
        hideIsShownTrueNotification(notification_id);
        voirProfile(medecin_id,'reception');
    }
    function IsShownTrueNotification(notification_id)
    {
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxIsShownTrueNotification') ?>',
            data: 'notification_id='+notification_id
        });
    };

    function hideNotification(notification_id)
    {
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxHideNotification') ?>',
            data: 'notification_id='+notification_id,
            success: function(data)
            {
                $("#notif_"+notification_id).remove();
            }
        });
    };

    function HideForSecretaires(medecin_id)
    {
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: '<?php echo url_for('@ajaxHideMedecin') ?>',
            data: 'medecin_id='+medecin_id,
            success: function(data) {
                $("#statut_medecin").replaceWith(
                '<a href="#" id="statut_medecin" onclick="javascript:ShowForSecretaires('+medecin_id+')">'+
                    '<div class="deconnecte" id="statut"></div></a>');
                for (i = 0; i < data.length; i++) {
                    if(document.getElementById('chatFriend_'+data[i]) != null){
                        // supprimer l'id de la session
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo url_for('@ajaxDeleteFromSession') ?>',
                            data: 'sender_id='+data[i]
                        });
                        $("#chatFriend_"+data[i]).remove();
                    }
                }
            }
        });
    };

    function ShowForSecretaires(medecin_id)
    {
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxShowMedecin') ?>',
            data: 'medecin_id='+medecin_id,
            success: function(data) {
                $("#statut_medecin").replaceWith(
                '<a href="#" id="statut_medecin" onclick="javascript:HideForSecretaires('+medecin_id+')">'+
                    '<div class="connecte" id="statut"></div></a>');
            }
        });
    };

    function HideForMedecins(medecin_id)
    {
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: '<?php echo url_for('@ajaxHideForMedecin') ?>',
            data: 'medecin_id='+medecin_id,
            success: function(data) {
                $("#statut_for_medecin").replaceWith(
                '<a href="#" id="statut_for_medecin" onclick="javascript:ShowForMedecins('+medecin_id+')">'+
                    '<div class="deconnecte" id="statut"></div></a>');
                for (i = 0; i < data.length; i++) {
                    if(document.getElementById('chatFriend_'+data[i]) != null){
                        // supprimer l'id de la session
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo url_for('@ajaxDeleteFromSession') ?>',
                            data: 'sender_id='+data[i]
                        });
                        $("#chatFriend_"+data[i]).remove();
                    }
                }
            }
        });
    };

    function ShowForMedecins(medecin_id)
    {
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxShowForMedecin') ?>',
            data: 'medecin_id='+medecin_id,
            success: function(data) {
                $("#statut_for_medecin").replaceWith(
                '<a href="#" id="statut_for_medecin" onclick="javascript:HideForMedecins('+medecin_id+')">'+
                    '<div class="connecte" id="statut"></div></a>');
            }
        });
    };

    function closeChatPanel(id)
    {
        // supprimer l'id de la session
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxDeleteFromSession') ?>',
            data: 'sender_id='+id
        });
        $("#chatFriend_"+id).remove();
    };

    function alertDesactivate()
    {
        // supprimer l'id de la session
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxAlert') ?>',
            data: 'is_active='+'false',
            success: function(data) {
                $('#alert_configure').replaceWith('<a id="alert_configure" class="mute" href="#" onclick="javascript:alertActivate()">Activer le son</a>');
            }
        });
    };

    function alertActivate()
    {
        // supprimer l'id de la session
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxAlert') ?>',
            data: 'is_active='+'true',
            success: function(data) {
                $('#alert_configure').replaceWith('<a id="alert_configure" class="sound" href="#" onclick="javascript:alertDesactivate()">Désactiver le son</a>');
            }
        });
    };

    function hideIsShownTrueNotification(notification_id)
    {
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxHideIsShownTrueNotification') ?>',
            data: 'notification_id='+notification_id,
            success: function(data)
            {
                $("#notif_"+notification_id).remove();
            }
        });
    };
    function hideNotification(notification_id)
    {
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxHideNotification') ?>',
            data: 'notification_id='+notification_id,
            success: function(data)
            {
            }
        });
    };

    function hideIsShownTrueNotificationConsultation(notification_id, patient_id)
    {
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxHideIsShownTrueNotification') ?>',
            data: 'notification_id='+notification_id,
            success: function(data)
            {
                $("#notif_"+notification_id).remove();
                newConsultation(patient_id);
            }
        });
    };

    function hideIsShownTrueNotificationCourrier(notification_id, courrier_id)
    {
        $.ajax({
            type: 'GET',
            url: '<?php echo url_for('@ajaxHideIsShownTrueNotification') ?>',
            data: 'notification_id='+notification_id,
            success: function(data)
            {
                $("#notif_"+notification_id).remove();
                courrier(courrier_id);
            }
        });
    };

    function newConsultation(patient_id)
    {
        window.location.href = ''+patient_id;
    };

    function courrier(courrier_id)
    {
        window.location.href = ''+courrier_id;
    };

    function remove()
    {
        $("#notif").remove();
    };

    function create( template, vars, opts ){
        return $container.notify("create",template, vars, opts);
    }

    function jouer_musique() {
        document.getElementById("musique").html('<p><object type="audio/mpeg" width="0" height="0" data="/musique/musique.mp3">'+
            '<param name="filename" value="/musique/musique.mp3" />'+
            '<param name="src" value="/musique/musique.mp3" />'+
            '<param name="autostart" value="true" />'+
            '<param name="loop" value="false" />'+
            '<param name="type" value="audio/mpeg" />'+
            '</object></p>');
    }
    function ajouterConfirmer(notification_id){
        $.ajax({
            url: '<?php echo url_for('@confirmerAjoutAmi') ?>',
            data: 'notification_id='+notification_id
        })
    }

</script>
